package com.knowif.backend.controller;

import com.knowif.backend.service.UserCollectService;
import com.knowif.pojo.TUser;
import com.knowif.search.SearchCondition;
import com.knowif.system.model.RestBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/wechat/collect")
public class UserCollectController {
	
	
	@Autowired
	private UserCollectService userCollectService;
	
	
	/**
	 * @author: xingyao 
	 * @Description:  用户收藏实现
	 * @param userId  收藏者id
	 * @param beUserId	被收藏者id
	 * @return
	 */
	@PostMapping("/addCollect")
	public RestBean<?> addCollect(Integer userId,Integer beUserId){
		if(userId == null || userId == 0){
			return RestBean.buildError("请输入userId");
		}
		if(beUserId == null || beUserId == 0){
			return RestBean.buildError("请输入被收藏者id");
		}
		try{
			return userCollectService.addCollect(userId, beUserId);
		}catch(Exception e){
			e.printStackTrace();
			return RestBean.buildError("操作失败");
		}
	}
	
	/**
	 * @author: xingyao 
	 * @Description:  查看用户收藏导师信息
	 * @param searchCondition
	 * @return
	 */
	@PostMapping("/selectCollect")
	public RestBean<?> selectCollect(@RequestBody SearchCondition searchCondition){
		return userCollectService.selectCollect(searchCondition);
	}
	
	
	/**
	 * @author: xingyao
	 * @Description:  删除用户收藏导师记录
	 * @param userCollectId
	 * @return
	 */
	@PostMapping("/deleteCollect")
	public RestBean<?> deleteCollect(@RequestBody Integer userCollectId){
		return userCollectService.deleteCollect(userCollectId);
	}
	
	
	
	/**
	 * @author: xingyao 
	 * @Description:  批量删除用户收藏导师记录
	 * @param userCollectIds
	 * @return
	 */
	@PostMapping("/deleteCollects")
	public RestBean<?> deleteCollect(@RequestBody List<Integer> userCollectIds){
		return userCollectService.deleteCollects(userCollectIds);
	}


}
